#pragma once

#include<iostream>
using namespace std;

bool Is_leap_year(int ii);
bool Is_31_days(int m);

class Date {
public:
    Date(int y, int m, int d);
    int days(int year, int month);
    void NewDay();
    void display()
    {
        cout << year << "-" << month << "-" << day << endl;
    }

private:
    int year; //年
    int month; //月
    int day;  // 日
};

Date::Date(int y = 1996, int m = 1, int d = 1)
{
    year = y;
    month = m;
    day = d;
    //if (y < 0) { cout << "Invalid month!"; year = 1996; }

    if (m < 0 || m>12) {
        cout << "Invalid month!" << endl; month = 1;//如果月份不合法
    }


    if (Is_31_days(m))
    {
        if (d < 0 || d>31) { cout << "Invalid day!" << endl; day = 1; }
    }
    else if (m == 2)
    {
        if (Is_leap_year(y))
        {
            if (d < 0 || d>29) { cout << "Invalid day!" << endl; day = 1; }
        }
        else {
            if (d < 0 || d>28) { cout << "Invalid day!" << endl; day = 1; }
        }
    }
    else
    {
        if (d < 0 || d>30) { cout << "Invalid day!" << endl; day = 1; }
    }

}

int Date::days(int year, int month)
{
    if (Is_31_days(month)) return 31;
    else if (month == 2)
    {
        if (Is_leap_year(year)) return 29;
        else return 28;
    }
    else return 30;

}


void Date::NewDay()
{
    if (Is_31_days(month))
    {
        if (day < 31)day++;
        else if (month != 12)
        {
            day = 1;
            month++;
        }
        else
        {
            year++;
            day = 1;
            month = 1;
        }

    }

    else if (month == 2)
    {
        if (Is_leap_year)
        {
            if (day < 29) day++;
            else {
                day = 1;
                month = 3;
            }

        }
        else {
            if (day < 28) day++;
            else {
                day = 1;
                month = 3;
            }
        }
    }

    else
    {
        if (day < 30)day++;
        else {
            day = 1;
            month++;
        }
    }

}

bool Is_leap_year(int ii)
{
    if (((ii % 4 == 0) && (ii % 100 != 0)) || (ii % 400 == 0))return 1;
    else return 0;
}

bool Is_31_days(int m)
{
    if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
        return 1;
    else
        return 0;
}

